		<script type="text/javascript">
			jQuery(document).ready(function($) {
				$('#filtros select').change(function(){
					var url = $(this).val(); // get selected value
					if (url) { // require a URL
					  window.location = url; // redirect
					}
					return false;
				})
			});
		</script>
<?php 
				$p = (isset($_GET['p'])) ? $_GET['p'] : '';
				$f = (isset($_GET['f'])) ? $_GET['f'] : '';
				$cat = 8;
				$cat_slug = 'produto';

				$categoria_atual = get_the_category();
				/*echo '<pre>';
				print_r($categoria_atual);
				echo '</pre>';*/
				//print_r($categoria_atual);
				if(!is_category()){
					foreach ($categoria_atual as $cat_atual) {
						if ($cat_atual->category_parent == 8) {
							$cat = $cat_atual->term_id;
							$cat_slug = $cat_atual->slug;
						}
					}
				}else{
					foreach ($categoria_atual as $cat_atual) {
						if ($cat_atual->name == single_cat_title('',false) ) {
							$cat_slug = $cat_atual->slug;
						}
						if ($cat_atual->category_parent == 8) {
							$cat = $cat_atual->term_id;
						}
					}
					
				}
					/*echo '<pre>';
					print_r($cat['0']);
					echo '</pre>';*/
 ?>
				<div id="filtros">
<?                      
						/* CATEGORIAS */

						$args = array(
                            'authors'      => '',
                            'child_of'     => 'produtos',
                            'date_format'  => get_option('date_format'),
                            'depth'        => 0,
                            'echo'         => 1,
                            'exclude'      => '',
                            'include'      => '',
                            'link_after'   => '',
                            'link_before'  => '',
                            'post_type'    => 'post',
                            'post_status'  => 'publish',
                            'show_date'    => '',
                            'sort_column'  => 'menu_order, post_title',
                            'title_li'     => __('Pages'), 
                            'walker'       => '',
                            'showposts'    =>-1
                        );
                        query_posts($args);
                        $paises = array();
						while ( have_posts() ) : the_post(); 
							$array = get_post_custom_values('ficha_tecnica_pais_de_origem'); 
							$pais_de_origem = $array[0];
							if (!in_array($pais_de_origem, $paises) && $pais_de_origem != '') {
								$paises[] = $pais_de_origem;
							}
						endwhile; // end of the loop.
                        wp_reset_query();
						$args = array(
                            'child_of'     => 'produtos',
                            'orderby'      => 'title',
                        	'order'        => 'ASC',
                            'depth'        => 0,
                            'exclude'      => '',
                            'include'      => '',
                            'link_after'   => '',
                            'link_before'  => '',
                            'post_type'    => 'post',
                            'post_status'  => 'publish',
                            'showposts'    => -1
                        );
                        query_posts($args);
                        $fabricantes = array();
						while ( have_posts() ) : the_post(); 
							$array = get_post_custom_values('fabricante'); 
							$fabricante = $array[0];
							if (!in_array($fabricante, $fabricantes) && $fabricante != '') {
								$fabricantes[trim($fabricante)] = get_the_title($fabricante);
							}
						endwhile; // end of the loop.
						asort($fabricantes);
						/*echo '<pre>';
						print_r($fabricantes);
						echo '</pre>';*/
						
						wp_reset_query();
?>
					<select name="categoria" id="">
						<option value="<?=get_bloginfo('wpurl');?>/category/produto"><?php echo attribute_escape(__('CATEGORIA')); ?></option>
<?php 					$args = array(
							'type'                     => 'post',
							'child_of'                 => 0,
							'parent'                   => 8,
							'orderby'                  => 'name',
							'order'                    => 'ASC',
							'hide_empty'               => 1,
							'hierarchical'             => 0,
							'exclude'                  => '',
							'include'                  => '',
							'number'                   => '',
							'taxonomy'                 => 'category',
							'pad_counts'               => false 

						);
						$selected = '';
						
						$categories= get_categories( $args );
						foreach ($categories as $category) {
							$selected = (trim($category->cat_name) == trim(single_cat_title('',false))) ? 'selected="selected"' : '';
							$option = '<option value="'.get_bloginfo('wpurl').'/category/'.$category->category_nicename.'" '.$selected. '>';
							$option .= $category->cat_name;
							$option .= '</option>';
							echo $option;
						}

?>
					</select>
					<select name="subcategoria" id="">
						<option value="<?=get_bloginfo('wpurl');?>/category/produto">SUBCATEGORIA</option>
<?php 					$args = array(
							'type'                     => 'post',
							'child_of'                 => $cat,
							'parent'                   => '',
							'orderby'                  => 'slug',
							'order'                    => 'ASC',
							'hide_empty'               => 1,
							'hierarchical'             => 0,
							'exclude'                  => '',
							'include'                  => '',
							'number'                   => '',
							'taxonomy'                 => 'category',
							'pad_counts'               => false 

						);
						$selected = '';
						$categories= get_categories( $args );
						foreach ($categories as $category) {
							echo $category->cat_name . '-' . single_cat_title('',false);
							$selected = (trim($category->cat_name) == trim(single_cat_title('',false))) ? 'selected="selected"' : '';
							if($category->category_parent != 8){
								$option = '<option value="'.get_bloginfo('wpurl' ).'/category/'.$category->category_nicename.'" '.$selected. '>';
								$option .= $category->cat_name;
								$option .= '</option>';
								echo $option;
							}
						}
?>
					</select>
					<select name="origem" id="">
						<option value="<?=get_bloginfo('wpurl');?>/category/produto" selected="selected">ORIGEM</option>
<?php 					$selected = '';
						foreach ($paises as $pais) {
							$selected = ($p == $pais) ? 'selected="selected"' : '';
							$option = '<option value="'.get_bloginfo('wpurl' ).'/category/'.$cat_slug.'/?p='.$pais.'&f='.$f.'" '.$selected. '>';
							$option .= $pais;
							$option .= '</option>';
							echo $option;
						}
 ?>
					</select>
					<select name="fabricante" id="">
						<option value="<?=get_bloginfo('wpurl');?>/category/produto">FABRICANTE</option>
<?php 					$selected = '';
						foreach ($fabricantes as $k => $fabricante) {
							$selected = ($f == $k) ? 'selected="selected"' : '';
							$option = '<option value="'.get_bloginfo('wpurl').'/category/'.$cat_slug.'/?p='.$p.'&f='.$k.'" '.$selected. '>';
							$option .= $fabricante;
							$option .= '</option>';
							echo $option;
						}
 ?>
					</select>
				</div>